<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="${servicePackageName}.mapper.sys.SysResourceMapper">

	<select id="selectUserResourceList" resultType="${servicePackageName}.dto.ResourceRoleTreeDto">
	<#noparse>
		SELECT
			t.id,t.resource_code AS resourceCode,t.resource_name AS resourceName,
			t.parent_id AS parentId,t.resource_type AS resourceType,t.resource_path AS resourcePath,t.sort_num AS sortNum
		FROM
			sys_resource  t
			LEFT JOIN sys_role_resource  t2 ON t.id = t2.resource_id
			LEFT JOIN sys_user_role  t3 ON t3.role_id = t2.role_id
			LEFT JOIN sys_role t4 ON t4.id = t3.role_id 
			WHERE t3.user_id = #{userId}
			AND t4.is_enable = 0
			AND t.is_enable = 0
	</#noparse>
	</select>
	
	<select id="getAllResource" resultType="${servicePackageName}.dto.ResouceTreeDto">
	<#noparse>
		SELECT id,resource_name,parent_id,sort_num,0 AS isShow FROM sys_resource WHERE is_enable = 0
	</#noparse>
	</select>
	
	<select id="getAllResourceWithUser" resultType="${servicePackageName}.dto.ResouceTreeDto">
	<#noparse>
			SELECT
		t.id,
		t.resource_name AS resourceName,
		t.parent_id AS parentId,
		t.sort_num AS sortNum,
		IF (ISNULL(t2.RESOURCE_ID) , 0 , 1 ) AS isShow
	FROM
		sys_resource t
		LEFT JOIN sys_role_resource t2 ON t.id = t2.resource_id AND t2.role_id = #{roleId}
	WHERE
		t.is_enable = 0
	</#noparse>
	</select>
	
	<select id="getMaxOrderNum" resultType="java.lang.Integer">
		SELECT IFNULL(MAX(sort_num),0) FROM sys_resource
	</select>
</mapper>
